import configparser
import datetime
import json

import requests

import api
from DBAction import DBAction
from live import Live, get_live_list
from member import Member
# api.start_schedule()
# m = Member(677404, 67275553)
# # m.get_fanpai_price()
#
# start_time = '2021-06-12 08:00:00'
# end_time = '2021-06-09 08:00:00'
# m.get_msg_between(start_time, end_time)
#m.get_msg_last2now()

#  实例化configParser对象
config = configparser.ConfigParser()
# -read读取ini文件
config.read(r'./config/config.ini', encoding='GB18030')
start_time = config.get('member', 'start_time')

config.set('member', 'end_time', start_time)

newstart = datetime.datetime.strptime(start_time, "%Y-%m-%d %H:%M:%S") + datetime.timedelta(days=1)
config.set('member', 'start_time', newstart.strftime("%Y-%m-%d %H:%M:%S"))

#保存修改
with open(r'./config/config.ini', "w") as fw:
    config.write(fw)  # 使用write将修改内容写到文件中，替换原来config文件中内容

# data = '{"status":200,"success":true,"message":"OK","content":{"status":1,"list":[{"key":1,"name":"普通","value":113},' \
#        '{"key":3,"name":"匿名","value":1314},{"key":2,"name":"私密","value":52}]}} '
# dd = json.loads(data)
# print(dd['content']['list'])
# for item in dd['content']['list']:
#     if item['name'] == '普通':
#         print(item['value'])
#     elif item['name'] == '匿名':
#         print(item['value'])
#     elif item['name'] == '私密':
#         print(item['value'])


# db = DBAction('pocket48')
# result = db.data_inquiry_all("select max(msg_time) from roommsg where roomid=67217577")
# print(result[0])
# for data in result:
#     print(data[0])
#     id = data[0]
#     time = data[1]
#     stiem = api.convert_timestamp_to_timestr(int(time))
#
#     db.data_operate("update live set start_time=%s where liveid=%s", (stiem, id))

# dic = {'serverId': 583432185686331392, 'msgidClient': '77842c27-0327-420b-9016-5a180d213505', 'msgTime': 1617030673290, 'msgType': 'TEXT', 'bodys': 'bubu～～✨', 'extInfo': '{"config":{"build":"210202","phoneName":"unknow","version":"6.1.1","mobileOperators":"中国联通","phoneSystemVersion":"14.3"},"roomId":"67256340","module":"session","sessionRole":2,"sourceId":"67256340","text":"bubu～～✨","bubbleId":"283923487550767108","keyWordStatus":false,"messageType":"TEXT","fromApp":"201811","user":{"roleId":3,"vip":false,"nickName":"GNZ48-郑丹妮","teamLogo":"/mediasource/teamLogo2/all/gnz48_n3.png","userId":327575,"avatar":"/20200602/15910922820262XpUPXAHgj.jpg"}}', 'privacy': False}
# id = json.loads(dic['extInfo'])['user']['userId']
#
# api.start_schedule()
# m = Member(327575, 67256340)
# # m.get_msg_last2now()
# m.get_msg_to_endtime('2021-03-20 00:00:00')

# url = 'https://nim.nosdn.127.net/NDA5MzEwOAu003du003d/bmltYV83MjUxOTcwMzIwXzE2MTYxNzQyMjcwMDFfNmM5NjYyMWYtNmE2Ny00NzA2LTkyNDItOWRiNmE3NGU3NzJh'
# img_name = './123.png'
# html = requests.get(url, verify=False)
# with open(img_name, 'wb') as f:
#     print(html.content)
#     f.write(html.content)
# f.close()

# api.start_schedule()
# livemap = {}
# n = 1
# while True:
#     get_live_list(livemap)
#     print("livemap length: ", len(livemap))
#     # 没有直播，慢慢延长到10分钟检查一次
#     if len(livemap) > 0:
#         n = 1
#     elif len(livemap) == 0 and n < 6:
#         n += 1
#     api.wait_random_time(100 * n)